package com.lili.collection.mq.config;

import com.lili.collection.core.config.OutputConfig;
import com.lili.collection.core.domain.CollectCommonConfig;
import com.lili.collection.core.plugins.OutputPlugin;
import com.lili.collection.core.support.ConfigFieldDef;
import com.lili.collection.mq.plugins.RabbitmqOutputPlugin;
import com.rabbitmq.client.Address;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 *描述: Rabbitmq插件配置
 *@date:2023/5/23  15:59
 *@author:lili
 */
@Slf4j
@Data
public class RabbitmqOutputConfig extends CollectCommonConfig implements OutputConfig {
    /**
     * 集群地址
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.LIST, required = true)
    private List<Address> addressList;

    /**
     * 虚拟机名称
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.STRING, required = true)
    private String virtualHost;

    /**
     * 用户名
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.STRING, required = true)
    private String username;

    /**
     * 密码
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.STRING, required = true)
    private String password;

    /**
     * 交换机名称
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.STRING, required = true)
    private String exchangeName;

    /**
     * 交换机类型
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.STRING, required = true)
    private String exchangeType;

    /**
     * 队列名称
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.LIST, required = true)
    private List<String> queueList;

    /**
     * 队列和交换机是否绑定: true:绑定/false:不维护绑定
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.BOOLEAN, required = false)
    private boolean queueExchangeBinded=false;

    /**
     * 是否开启事务
     */
    @ConfigFieldDef(type = ConfigFieldDef.Type.BOOLEAN, required = false)
    private boolean enableTransaction=false;

    @Override
    public void setEnableTransaction(boolean enableTransaction) {
        this.enableTransaction = enableTransaction;
    }

    public boolean isEnableTransaction() {
        return enableTransaction;
    }

    @Override
    public OutputPlugin getPlugin() {
        return new RabbitmqOutputPlugin();
    }
}